
********************************************************************************
$ontext
This is the numerical bottom-up optimization model used in
St�ckl, F. and A. Zerrahn (2020): Substituting Clean for Dirty Energy: A Bottom-Up Analysis

This model is derived from
The Dispatch and Investment Evaluation Tool with Endogenous Renewables (DIETER).
Version 1.3.0, November 2018.
Written by Alexander Zerrahn and Wolf-Peter Schill.

This work is licensed under the MIT License (MIT).
For more information on this license, visit http://opensource.org/licenses/mit-license.php.
Whenever you use this code, please refer to http://www.diw.de/dieter.
We are happy to receive feedback under azerrahn@diw.de and wschill@diw.de.
$offtext
********************************************************************************




**************************
***** GLOBAL OPTIONS *****
**************************

* Set star to skip Excel upload and load data from gdx
$setglobal skip_Excel ""

* Choose base year
$setglobal base_year "'2030'"

* Set star to select run-of-river options
$setglobal ror_variable "*"

* Set star to determine loops, otherwise default 100% renewables
$setglobal loop_over_renewable_share "*"

* Set star for no crossover to speed up calculation time by skipping crossover in LP solver
$setglobal no_crossover ""

* Set star for reporting to Excel
$setglobal report_to_excel "*"

* Set star for extension with electrification
$setglobal power_to_x ""


********************************************************************************


****************************
***** INITIALIZE LOOPS *****
****************************

sets
%loop_over_renewable_share%$ontext
loop_res_share   Solution loop for different shares of renewables       /1*1/
$ontext
$offtext
;




********************************************************************************

**************************
***** SOLVER OPTIONS *****
**************************

options
optcr = 0.00
reslim = 10000000
lp = cplex
mip = cplex
nlp = conopt
limrow = 0
limcol = 0
;

options
dispwidth = 15
limrow = 0
limcol = 0
solprint = off
sysout = off
;




********************************************************************************

**************************
***** Dataload *****
**************************

$include dataload.gms
*$stop



********************************************************************************

*************************************
***** Features for single nodes *****
*************************************

Set
map_n_tech(n,tech)
map_n_sto(n,sto)
;

map_n_tech(n,tech) = yes$nu_p(n,tech) ;
map_n_sto(n,sto) = yes$nu_sto_p(n,sto) ;
;




********************************************************************************

***************************
***** Initialize data *****
***************************

* Parameters for default base year
delta(n,h) = delta_y(n,%base_year%,h) ;
phi_res(n,res,h) = phi_res_y(n,%base_year%,res,h) ;


* Set loop parameters to default zero
iota = 0 ;



********************************************************************************
***** Model *****
********************************************************************************

$include model.gms
*$stop



********************************************************************************
***** Options, fixings, report preparation *****
********************************************************************************

* Solver options
$onecho > cplex.opt
lpmethod 4
threads 4
epgap 1e-3
$offecho

%no_crossover%$ontext
$onecho > cplex.opt
lpmethod 4
threads 4
epgap 1e-3
barcrossalg -1
barepcomp 1e-8
$offecho
$ontext
$offtext

dieter.OptFile = 1;
dieter.holdFixed = 1 ;




********************************************************************************
***** Solve *****
********************************************************************************

* Preparation of GUSS tool for scenario analysis
iota = eps ;

$eval superscencount 1000

Set
modelstats       model stats collection                  /modelstat, solvestat, resusd/
superscen        Scenarios                               /scen1*scen%superscencount%/
map(superscen,loop_res_share)    /#superscen:(#loop_res_share)/
;

set
scen(superscen);
scen(superscen) = yes$( sum((loop_res_share) , map(superscen,loop_res_share)) )    ;

Parameters
gussoptions                              /Logoption 2, Optfile 1, Skipbasecase 1/
modstats(superscen, modelstats)
min_res
;

min_res(scen) = sum( (loop_res_share)$map(scen,loop_res_share) , loop_res_share.val/10000 ) ;


Parameters
lev_Z(superscen)
lev_G(superscen,n,tech,h)
lev_G_RES(superscen,n,tech,h)
lev_STO_IN(superscen,n,sto,h)
lev_STO_OUT(superscen,n,sto,h)
lev_STO_L(superscen,n,sto,h)
lev_N_TECH(superscen,n,tech)
lev_N_STO_E(superscen,n,sto)
lev_N_STO_P_IN(superscen,n,sto)
lev_N_STO_P_OUT(superscen,n,sto)

%power_to_x%$ontext
lev_D_X(superscen,n,h)
$ontext
$offtext
;


* Inclusion of scenario and fixing
$include fix.gms
$include scenario.gms

*$stop

* Definition of dictionary set for GUSS tool
Set dict(*,*,*) /
scen             .scenario       .''
gussoptions      .opt            .modstats

iota             .param          .min_res

Z                .level          .lev_Z
G                .level          .lev_G
G_RES            .level          .lev_G_RES
STO_IN           .level          .lev_STO_IN
STO_OUT          .level          .lev_STO_OUT
STO_L            .level          .lev_STO_L
N_TECH           .level          .lev_N_TECH
N_STO_E          .level          .lev_N_STO_E
N_STO_P_IN       .level          .lev_N_STO_P_IN
N_STO_P_OUT      .level          .lev_N_STO_P_OUT

%power_to_x%$ontext
D_X              .level          .lev_D_X
$ontext
$offtext
/
;


solve DIETER using lp min Z scenario dict;

%report_to_excel%$ontext
$include report_to_excel.gms
$ontext
$offtext


* ---------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------- *
